package main

import (
	"flag"
	"fmt"
	"go-exp/exp-test/nacos-test/client_demo/internal/config"
	"go-exp/exp-test/nacos-test/client_demo/internal/handler"
	"go-exp/exp-test/nacos-test/client_demo/internal/svc"
	"os"

	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/rest"
)

var configFile = flag.String("f", "exp-test/nacos-test/client_demo/etc/clientdemo-api.yaml", "the config file")

func main() {
	flag.Parse()
	// 重要 设置nacos初始启动时不读取缓存
	os.Setenv("NACOS_NOT_LOAD_CACHE_AT_START", "true")

	// 这里可以读取nacos上的配置文件
	var c config.Config
	conf.MustLoad(*configFile, &c)

	server := rest.MustNewServer(c.RestConf)
	defer server.Stop()

	ctx := svc.NewServiceContext(c)
	handler.RegisterHandlers(server, ctx)

	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
	server.Start()
}
